//
//  JQFYAvtivityTableViewCell.m
//  JQFY
//
//  Created by apple on 2017/10/8.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYAvtivityTableViewCell.h"

@interface JQFYAvtivityTableViewCell ()

@property (nonatomic ,strong) UIImageView *bgView;
@property (nonatomic ,strong) UIImageView *iconImg;
@property (nonatomic ,strong) UILabel *dateLabel;
@property (nonatomic ,strong) UILabel *nameLabel;
@property (nonatomic ,strong) UILabel *addressLabel;
@property (nonatomic ,strong) UILabel *priceLabel;
@end

@implementation JQFYAvtivityTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}

//布局视图
-(void) setupUI{
    self.backgroundColor = [UIColor clearColor];
    
    _bgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView).mas_offset(-10 *SCAL);
        make.leading.mas_equalTo(self.contentView).mas_offset(10 *SCAL);
        make.trailing.mas_equalTo(self.contentView).mas_offset(-10 *SCAL);
    }];
    UIImage *bgimg = [UIImage imageNamed:@"avtivityCell_bg"];
    _bgView.layer.contents = (id)bgimg.CGImage;
    //设置icon
    _iconImg = [[UIImageView alloc] init];
    [_bgView addSubview:_iconImg];
    [_iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.equalTo(_bgView).mas_offset(10 *SCAL);
        make.bottom.equalTo(_bgView).mas_offset(-10 *SCAL);
        make.width.mas_offset(70 *SCAL);
    }];
    [_iconImg setImage:[UIImage imageNamed:@"avtivityCell_icon"]];
    //datebg
    UIImageView *dateImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avtivityCell_dateBg"]];
    [_bgView addSubview: dateImg];
    [dateImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_bgView).mas_offset(10 *SCAL);
        make.leading.equalTo(_iconImg.mas_trailing).mas_offset(10 *SCAL);
        make.width.mas_offset(46 *SCAL);
        make.height.mas_offset(13 *SCAL);
    }];
    //日期
    _dateLabel = [[UILabel alloc] init];
    [dateImg addSubview:_dateLabel];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(dateImg);
    }];
    _dateLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:10 *SCAL];
    _dateLabel.textColor = [UIColor whiteColor];
    _dateLabel.textAlignment = NSTextAlignmentCenter;
    _dateLabel.layer.cornerRadius = 2 *SCAL;
    _dateLabel.layer.masksToBounds = YES;
    _dateLabel.text = @"spr 12";
    //活动名称
    _nameLabel = [[UILabel alloc] init];
    [_bgView addSubview:_nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(_dateLabel);
        make.top.mas_equalTo(_dateLabel.mas_bottom).mas_offset(5 *SCAL);
        make.trailing.mas_equalTo(_bgView).mas_offset(-20 *SCAL);
    }];
    _nameLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15 *SCAL];
    _nameLabel.textColor = [UIColor blackColor];
    _nameLabel.textAlignment = NSTextAlignmentLeft;
    _nameLabel.numberOfLines = 2;
    _nameLabel.text = @"2017 UNINHIBITED NIGTH";
    //地址
    _addressLabel = [[UILabel alloc] init];
    [_bgView addSubview:_addressLabel];
    [_addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(_dateLabel);
        make.trailing.mas_equalTo(_bgView);
        make.bottom.mas_equalTo(_iconImg).mas_offset(-5 *SCAL);
    }];
    _addressLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:8 *SCAL];
    _addressLabel.textColor = [UIColor grayColor];
    _addressLabel.textAlignment = NSTextAlignmentLeft;
    _addressLabel.text = @"上海 UNINHIBITED CLUB";
    //价格label
    _priceLabel = [[UILabel alloc] init];
    [_bgView addSubview:_priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_addressLabel).offset(-5);
        make.bottom.equalTo(_addressLabel.mas_top).mas_offset(-5 *SCAL);
        make.width.mas_offset(150 *SCAL);
        make.height.mas_offset(19 *SCAL);
    }];
    _priceLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:15 *SCAL];
    _priceLabel.textColor = [UIColor purpleColor];
    _priceLabel.textAlignment = NSTextAlignmentLeft;
    _priceLabel.text = @"9999 元";
    
    //了解更多
//    UIImageView *moreImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"avtivityCell_more"]];
//    [_bgView addSubview:moreImg];
//    [moreImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.mas_offset(46 *SCAL);
//        make.height.mas_offset(17 *SCAL);
//        make.trailing.mas_equalTo(_bgView).offset(-15 *SCAL);
//        make.bottom.mas_equalTo(_addressLabel);
//    }];
}
- (void)setModel:(JQFYActivityListModel *)model {
    if (_model == model) {
        return;
    }
    _model = model;
    [_iconImg sd_setImageWithURL:[NSURL URLWithString:model.tickets_cover] placeholderImage:[UIImage imageNamed:@"avtivityCell_icon"]];
    _dateLabel.text = model.tickets_time;
    _nameLabel.text = model.tickets_title;
    _addressLabel.text = model.tickets_address;
    _models = model.start_time;
    NSMutableArray *ticketsarray = [NSMutableArray new];
    for (JQFYTicketInfoModel *infoModel in _models) {
        [infoModel.ticket enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [ticketsarray addObject:obj];
        }];
    }
    _buyModels = ticketsarray;
    __block NSString *priceStr;
    [_buyModels enumerateObjectsUsingBlock:^(JQFYTicketInfo_BuyModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        //遍历拼接价格
        if (idx == 0) {
            priceStr = [NSString stringWithFormat:@" %@ ", obj.price];
        } else {
            priceStr = [NSString stringWithFormat:@"%@ / %@", priceStr, obj.price];
        }
    }];
    _priceLabel.text = priceStr;//重新赋值价格
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
